package models;

import java.io.FileNotFoundException;
import java.io.IOException;

import org.jdom2.JDOMException;

import objects.Lexicon;

/* Reads from and Writes to XML files */
public class LexiconModel {
	
	/* static lexicon variable to remove need for creating LexiconModel objects */
	private static Lexicon lexicon;
	
	public LexiconModel() {}
	
	public static void read() throws IOException, JDOMException {
		LexiconXMLReader reader = new LexiconXMLReader();
		reader.read(LexiconFileModel.getFile());
		lexicon = reader.getLexicon();
	}
	
	public static void write() throws FileNotFoundException, IOException {
		LexiconXMLWriter writer = new LexiconXMLWriter();
		writer.setDatabase(lexicon);
		writer.write(LexiconFileModel.getFile());
	}
	
	/** Get/Set data **/
	
	public static void setLexicon(Lexicon newLexicon) {
		lexicon = newLexicon;
	}
	
	public static Lexicon getLexicon() {
		return lexicon;
	}
}
